<?php
namespace Core\common;

use Core\Traits\Template;

class Controller
{
    use Template;

    public $controller;
    public $action;
    public $static;
    
    function __construct()
    {

        $do = Request::params('do') == 'index'?'index/index':Request::params('do');
        $controller = explode("/",$do);
        $do = $controller[0];
        $op = $controller[1];

        $static = MODULE_URL.Assist::globalVal('yWe7.static').'/';
        $this->controller = $do;
        $this->action = $op;
        $this->static = $static;
    }

    /**
     * 渲染视图
     * @param string $view 视图名
     * @param array $data 发送数据
     * @param string $module
     */
    public function display($view = '', $data = [],$module = '')
    {
        

        if($view && strpos($view,'/') === false){
            $do = $this->controller;
            $view = $do.'/'.$view;
        }
        if(empty($view)){
            $view = $this->controller.'/'.$this->action;
        }
        $data['static'] = $this->static;
        $data['__static__'] = $this->static;

        echo $this->fetch($view,$data);
    }

    /**
     * @param $name
     * @return mixed|string
     */
    public static function template($name)
    {
        return template($name,TEMPLATE_INCLUDEPATH);
    }
}